package edu.pku.sei.transformation.editor.model.execution;

import java.util.ArrayList;

import org.w3c.dom.Element;

import edu.pku.sei.modeler.model.core.MetaModelElement;
import edu.pku.sei.modeler.model.xml.XMLUtility;
import edu.pku.sei.transformation.editor.model.ModelPackage;


public class ObjectNode extends MetaModelElement implements IObjectNode{
	protected ArrayList outgoingObjectFlows = new ArrayList();
	protected ArrayList incomingObjectFlows = new ArrayList();
	@Override
	public ArrayList getIncomings() {
		return incomingObjectFlows;
	}

	@Override
	public ArrayList getOutgoings() {
		return outgoingObjectFlows;
	}
	
	@Override
	public void serialize(Element root) {
		super.serialize(root);
		XMLUtility.xmlInstance.serializeNodes(root,
				ModelPackage.NODE_OUTGOINGS, this.outgoingObjectFlows);
		XMLUtility.xmlInstance.serializeNodesNotContain(root,
				ModelPackage.NODE_INCOMINGS, this.incomingObjectFlows);
	}

	@Override
	public void deSerialize(Element root) {
		super.deSerialize(root);
		this.outgoingObjectFlows.addAll(XMLUtility.xmlInstance
				.deSerializeNodes(root, ModelPackage.NODE_OUTGOINGS));
		this.incomingObjectFlows.addAll(XMLUtility.xmlInstance
				.deSerializeNodesNotContain(root, ModelPackage.NODE_INCOMINGS,
						this));
	}

	@Override
	public void dynamicSet(String featureID, Object value) {
		if (ModelPackage.NODE_INCOMINGS.equals(featureID)) {
			this.incomingObjectFlows.add(value);
		} else if (ModelPackage.NODE_OUTGOINGS.equals(featureID)) {
			this.outgoingObjectFlows.add(value);
		} else {
			super.dynamicSet(featureID, value);
		}
	}
}
